package com.nchu.controller;

import com.nchu.entity.TbSpecification;
import com.nchu.service.TbSpecificationService;
import com.nchu.util.PageResult;
import com.nchu.util.R;
import com.nchu.vo.TbSpecificationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/specification")
//@CrossOrigin
public class TbSpecificationController {
    @Autowired
    private TbSpecificationService tbSpecificationService;
    @GetMapping("/list")
    public List<TbSpecification> list(){
        return tbSpecificationService.findAll();
    }
    @GetMapping("/findByPage")
    public PageResult<TbSpecification> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return tbSpecificationService.findByPage(page,pageSize);
    }
    @PostMapping("/search")
    public PageResult<TbSpecification> search(@RequestParam("page") Integer page,
                                      @RequestParam("pageSize") Integer pageSize,
                                      @RequestBody(required = false) TbSpecificationVO tbSpecificationVO){
        return tbSpecificationService.search(page,pageSize,tbSpecificationVO);
    }

    @PostMapping("/save")
    public R save(@RequestBody TbSpecification tbSpecification){
        return tbSpecificationService.save(tbSpecification) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
}
